﻿using System.Configuration;

namespace GT.Framework.RabbitMQ.Core
{
    public sealed class RabbitMQConfig : ConfigurationSection
    {
        public static RabbitMQConfig GetConfig()
        {
            RabbitMQConfig section = GetConfig("RabbitMQConfig");
            return section;
        }

        public static RabbitMQConfig GetConfig(string sectionName)
        {
            RabbitMQConfig section = (RabbitMQConfig)ConfigurationManager.GetSection(sectionName);
            if (section == null)
                throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
            return section;
        }

        /// <summary>
        /// 可写的RabbitMQ链接地址
        /// </summary>
        [ConfigurationProperty("ServerConStr", IsRequired = false)]
        public string ServerConStr
        {
            get
            {
                return (string)base["ServerConStr"];
            }
            set
            {
                base["ServerConStr"] = value;
            }
        }

        /// <summary>
        /// 可写的RabbitMQ链接地址
        /// </summary>
        [ConfigurationProperty("UserName", IsRequired = false)]
        public string UserName
        {
            get
            {
                return (string)base["UserName"];
            }
            set
            {
                base["UserName"] = value;
            }
        }

        /// <summary>
        /// 可写的RabbitMQ链接地址
        /// </summary>
        [ConfigurationProperty("Password", IsRequired = false)]
        public string Password
        {
            get
            {
                return (string)base["Password"];
            }
            set
            {
                base["Password"] = value;
            }
        }

        /// <summary>
        /// 可写的RabbitMQ链接地址
        /// </summary>
        [ConfigurationProperty("RequestedHeartbeat", IsRequired = false)]
        public ushort RequestedHeartbeat
        {
            get
            {
                return (ushort)base["RequestedHeartbeat"];
            }
            set
            {
                base["RequestedHeartbeat"] = value;
            }
        }


    }
}
